﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TodoApp.Enum;
using TodoApp.GoodsModel;
using TodoApp.TodoGoodsDTO;
using Volo.Abp.Domain.Repositories;

namespace TodoApp
{
    public class GoodsService : Volo.Abp.Application.Services.ApplicationService, IGoodsService
    {
        /// <summary>
        ///  注入 
        /// </summary>
        private readonly IRepository<TodoGoods, Guid> _todoGoodsDTOs;

        public GoodsService(IRepository<TodoGoods, Guid> todoGoodsDTOs) {
            _todoGoodsDTOs = todoGoodsDTOs;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<ShopStatus> CreateAsync( GoodsAddDTO model )
        {
           await _todoGoodsDTOs.InsertAsync(ObjectMapper.Map<GoodsAddDTO , TodoGoods>(model));

            return ShopStatus.Succeed;

        }
        /// <summary>
        ///  删除 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        public async Task DeleteAsync(Guid id)
        {
            await _todoGoodsDTOs.DeleteAsync(id);
        }


        /// <summary>
        ///  显示 
        /// </summary>
        /// <returns></returns>
        public async Task<List<GoodsShowDTO>> GetListAsync()
        {
            var list = await _todoGoodsDTOs.GetListAsync();
            var model = ObjectMapper.Map<List<TodoGoods>, List<GoodsShowDTO>>(list);
            return model;

        }
        /// <summary>
        ///  详情 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<GoodsShowDTO> FileCategory(Guid id)
        {
            //   利用 find 查询 数据 
            var str = await _todoGoodsDTOs.FindAsync(id);
            return ObjectMapper.Map<TodoGoods, GoodsShowDTO>(str);
        }

        /// <summary>
        ///  修改 
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>

        public async Task<ShopStatus> UpdateGoods(GoodsAddDTO model)
        {
          
            await _todoGoodsDTOs.UpdateAsync(ObjectMapper.Map<GoodsAddDTO, TodoGoods>(model));
            return ShopStatus.Succeed;
        }
}    }

